package com.elinkway.infinitemovies.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;

import com.le123.ysdq.R;

/**
 * Author: liuxiaojiang(liuxiaojiang@lvideo.com)
 * Date: 2016-04-05
 * Time: 16:11
 * Description: FIXME
 */
public class LiteProgressDialog extends Dialog {
    private Context context;
    private int progressIndex = 0;
    ProgressBar mProgress;

    public LiteProgressDialog(Context context) {
        super(context);
        this.context = context;
    }

    public LiteProgressDialog(Context context, int theme) {
        super(context, theme);
        this.context = context;
    }

    protected LiteProgressDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.dialog_liteapp_progress, null);
        setContentView(view);


        mProgress = (ProgressBar) view.findViewById(R.id.lite_progress_bar);
        mProgress.setProgress(progressIndex);
        changeProgress();
    }

    private void changeProgress() {

        new Handler().postDelayed(new Runnable(){
            public void run() {
                if(progressIndex < 80){
                    progressIndex = progressIndex + 15;
                    mProgress.setProgress(progressIndex);
                    changeProgress();
                }
            }
        }, 500);
    }
}
